<template>
	<view v-if="content.length > 0">
		<view class="BigBox" v-for="(item, index) in content" :key="item.rId">
			<view class="Top">
				<view class="Info" @click="toInfo" :id="item.rId">
					<view class="InfoName center">电脑种类 -
						{{ item.rpcType === 1 ? '笔记本' : item.rpcType === 2 ? '台式' : '未知种类' }}
					</view>
					<view class="InfoDay">电脑名称 : {{ item.rpcName }}</view>
					<view class="InfoPrice">预约时间:{{item.rreserveTime}}</view>
					<!-- <view class="OutTradeNo">平台订单号 : {{ item.rid }}</view> -->
				</view>
				<button v-if="tabId===1" @click="pending" class="verify-button" :data-ropenid="item.ropenid"
					:data-rid="item.rId">接单</button>
				<button v-if="tabId===2" @click="accept" class="verify-button" :data-rid="item.rId">完成</button>
			</view>
		</view>
	</view>
	<view v-else class="no-info">还没有订单信息哦！</view>
</template>

<script>
	import API from '../../../api/api';
	import '../../../common/css/pending-item.scss'
	export default {
		props: {
			content: {
				type: Array,
				default: () => []
			},
			tabId: {
				type: Number,
				required: true
			}
		},
		data() {
			return {

			}
		},
		methods: {
			toInfo(event) {
				let id = event.currentTarget.id;
				// console.log(id)
				uni.navigateTo({
					url: '/pages/repair/component/repair-item?id=' + id
				})
			},
			async pending(event) {
				let ropenid = event.currentTarget.dataset.ropenid
				let id = event.currentTarget.dataset.rid;
				let token = uni.getStorageSync("token")
				// console.log((ropenid))
				const acceptRes = await API.AcceptRepair(id, token)
				if (acceptRes.code === 1) {
					uni.showToast({
						title: '接单成功',
						icon: 'none'
					})
					const res = await API.getUserPhone(ropenid)
					if (res.code === 1) {
						uni.setClipboardData({
							data: res.data,
							success() {
								uni.showToast({
									title: '已复制用户联系方式',
									icon: 'none'
								}, 2000)
							}
						})
						uni.switchTab({
							url: '/pages/My/My'
						})
					} else {
						uni.showToast({
							title: '复制失败',
							icon: 'none'
						})
					}
				} else {
					uni.showToast({
						title: '接单失败',
						icon: 'none'
					})
				}
			},
			async accept(event) {
				let id = event.currentTarget.dataset.rid;
				let token = uni.getStorageSync("token")
				const res = await API.UpdateRepairFinish(id,token)
				if(res.code===1){
					uni.showToast({
						title:'完成订单',
						icon:'none'
					},2000)
					uni.switchTab({
						url:'/pages/My/My'
					})
				}
			}
		},
	}
</script>

<style>

</style>